package org.flower.entity;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Aizen
 */
public class PageBean<T> {
    /**
     * 总记录数
     */
    private int totalCount;
    /**
     * 总页数
     */
    private int totalPage;
    /**
     * 每页的数据
     */
    private List<T> list;
    /**
     * 当前页码
     */
    private int currentPage;
    /**
     * 每页记录数
     */
    private int rows;
    /**
     * 开始时的条数
     */
    private int start;

    /**
     * 要展示的所有的页码
      */
    private List<Integer> pageNums;
    /**
     * 下一页
     */
    private Integer nextPageNum;
    /**
     * 上一页
     */
    private Integer prePageNum;
    /**
     * 设置默认展示的多少个页码
     */
    private Integer pNum = 10;


    public void init() {

        //设置要展示的页码
        pageNums = new ArrayList();
        int startNum=1;
        int endNum=pNum;

        if (currentPage <= (pNum/2)) {
            startNum = 1;
            if(totalPage<pNum){
                endNum = totalPage;
            }else{
                endNum = pNum;
            }
        } else if (currentPage >= (totalPage - (pNum/2))){
            startNum = totalPage - pNum + 1;
            endNum = totalPage;
        } else {//前不着村后不着店
            startNum = currentPage - (pNum / 2);
            endNum = currentPage + (pNum / 2);
        }

        for (int i = startNum; i <= endNum ; i++) {
            pageNums.add(i);
        }

        //设置上一页和下一页
        nextPageNum = currentPage + 1 > totalPage ? totalPage : currentPage + 1;
        prePageNum = currentPage - 1 <= 0 ? 1 : currentPage - 1;

    }

    public List<Integer> getPageNums() {
        return pageNums;
    }

    public void setPageNums(List<Integer> pageNums) {
        this.pageNums = pageNums;
    }

    public Integer getNextPageNum() {
        return nextPageNum;
    }

    public void setNextPageNum(Integer nextPageNum) {
        this.nextPageNum = nextPageNum;
    }

    public Integer getPrePageNum() {
        return prePageNum;
    }

    public void setPrePageNum(Integer prePageNum) {
        this.prePageNum = prePageNum;
    }

    public Integer getpNum() {
        return pNum;
    }

    public void setpNum(Integer pNum) {
        this.pNum = pNum;
    }

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    @Override
    public String toString() {
        return "PageBean{" +
                "totalCount=" + totalCount +
                ", totalPage=" + totalPage +
                ", list=" + list +
                ", currentPage=" + currentPage +
                ", rows=" + rows +
                ", start=" + start +
                '}';
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public PageBean(int totalCount, int totalPage, List<T> list, int currentPage, int rows) {
        this.totalCount = totalCount;
        this.totalPage = totalPage;
        this.list = list;
        this.currentPage = currentPage;
        this.rows = rows;
    }

    public PageBean() {
    }

}
